{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "!rm -rf build\n",
    "!wget -q -O frontend.zip https://github.com/vanpelt/emotion-detector/releases/download/stable/frontend.zip\n",
    "!unzip -q frontend.zip"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Serve our custom UI\n",
    "!cp -r app/models/ build/\n",
    "from subprocess import Popen\n",
    "try:\n",
    "    server.kill()\n",
    "except NameError:\n",
    "    pass\n",
    "port = 8010\n",
    "server = Popen([\"cd ./build && python -m http.server %i\" % port], shell=True,\n",
    "               stdin=None, stdout=None, stderr=None, close_fds=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import IPython\n",
    "import getpass\n",
    "username = getpass.getuser()\n",
    "html = open(\"./build/index.html\").read()\n",
    "body = html.replace('=\"/', '=\"https://hub2.wandb.us/user/{}/proxy/{}/'.format(username,port),10)\n",
    "body = body.replace(\"</head>\", '<script type=\"text/javascript\"/>window.BASE_URL = \"https://hub2.wandb.us/user/{}/proxy/{}/\"</script></head>'.format(username,port))\n",
    "display(IPython.display.HTML(body))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
